package dRegAut.opg2;

import java.util.Arrays;
import java.util.HashSet;

public class MartinOpg3_7 {
    public NFA setupNFA_3_7() {
        // Example 3.7 page 97
        NFA m = new NFA();
        State state0 = new State("0");
        State state1 = new State("1");
        State state2 = new State("2");
        State state3 = new State("3");
        State state4 = new State("4");

        m.alphabet = new Alphabet("ba");

        m.states.add(state0);
        m.states.add(state1);
        m.states.add(state2);
        m.states.add(state3);
        m.states.add(state4);

        m.initial = state0;
        m.accept.add(state4);

        addTransition(m, state0, 'a', state1, state2);
        addTransition(m, state0, 'b', state4);
        addTransition(m, state1, 'a', state0);
        addTransition(m, state2, 'a', state3);
        addTransition(m, state3, 'b', state0);

        return m;
    }

    private void addTransition(NFA nfa, State fromState, char c, State... toStates) {
        StateSymbolPair ssp = new StateSymbolPair(fromState, c);
        nfa.transitions.put(ssp, new HashSet<State>(Arrays.asList(toStates)));
    }
}
